<?php

$url = "http://网关域名/api/order/rudan";
$key = "秘钥";
$data0 = [
    'pid'           => "Pid",
    'type'  => 'wxpay',
    'out_trade_no'  => '订单号',
    'notify_url'    => '回调地址',
    'return_url'    => '同步跳转',
    'name'          => '1',
    'money'         => 5
    ];
$sign = $this->k_d_markSign($data0,$key);
$data = [
    'pid'           => "Pid",
    'type'          => 'wxpay',
    'out_trade_no'  => '订单号',
    'notify_url'    => '', //回调地址
    'return_url'    => '',//同步跳转
    'name'          => '1',
    'money'         => 5,
    'sign_type'     => 'MD5'
    ];
    
$data['sign'] = $sign;

$info_url = $url."?pid={$data['pid']}&type=wxpay&out_trade_no=$no&notify_url={$data['notify_url']}&return_url={$data['return_url']}&name={$data['name']}&money={$money}&sign={$data['sign']}";
        
header("location:$info_url");
    

function k_d_markSign($paydata, $signkey) {
    ksort ( $paydata );
    $str = '';
    foreach ( $paydata as $k => $v ) {
        $str .= $k . "=" . $v . "&";
    }   
    $str = (substr($str,0,-1));
    return  ( md5 ( $str  . $signkey ) );
}

//url请求
function k_d_curlRequest($url, $data = [], $headers = [], $timeout = 10, $method = 'GET')
{                                              
    $curl = curl_init();
    if (!empty($headers)) {
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    }

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

    if (!empty($data) && 'GET' == $method) $method = 'POST';

    switch ($method) {
        case 'POST':
            curl_setopt($curl, CURLOPT_POST, 1);   
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);  
            break;
        case 'PUT':
            curl_setopt($curl, CURLOPT_PUT, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
        case 'DELETE':
            curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
            break;
    }   
    
    curl_setopt($curl, CURLOPT_USERAGENT,"Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2");

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   
    $output = curl_exec($curl); 

    if (curl_errno($curl)) {
        echo 'Curl error: ' . curl_error($curl);exit;
    }   
    curl_close($curl);

    return $output;
}